$(document).ready(function() {
	init_photo_slies();
    update_product_description();
    init_product_description_event();
});

function init_photo_slies() {
	$('#products').slides({
		preload: true,
		preloadImage: 'themes/img/loading.gif',
		effect: 'slide, fade',
		crossfade: true,
		slideSpeed: 350,
		fadeSpeed: 500,
		generateNextPrev: true,
		generatePagination: false
	});
}

function init_product_description_event() {
    init_prev_event();
    init_next_event();
    init_pagination_event();
}

function init_prev_event() {
    $('.prev').click(function() {
        update_product_description();
    });
}

function init_next_event() {
    $('.next').click(function() {
        update_product_description();
    });
}

function init_pagination_event() {
    $('ul.pagination > li > a').each(function(index) {
        $(this).click(function() {
            update_product_description();
        });
    });
}

function update_product_description() {
    var i = get_product_id();
    $('#product-descriptions > div').each(function(index) {
        if (index == i) {
            $(this).css('display', 'block');
        } else {
            $(this).css('display', 'none');
        }
    })
}

function get_product_id() {
    var product_id = 0;
    $('ul.pagination > li').each(function(index) {
       if ($(this).hasClass("current")) {
           product_id = index;
       } 
    });
    return product_id;
}